package com.itycu.server.service.business;

import java.util.List;
import com.itycu.server.utils.DateUtils;
import com.itycu.server.dto.business.PraSaleDto;
import com.itycu.server.core.AbstractService;
import com.itycu.server.utils.SecurityUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.itycu.server.mapper.business.PraSaleMapper;
import com.itycu.server.domain.business.PraSale;

/**
 * 销售订单Service业务层处理
 *
 * @author itycu
 * @date 2025-02-18
 */
@Service("praSaleService")
public class PraSaleService extends AbstractService<PraSale> {
    @Resource
    private PraSaleMapper praSaleMapper;

    /**
     * 查询销售订单列表
     *
     * @param praSale 销售订单
     * @return 销售订单
     */
    public List<PraSaleDto> list(PraSale praSale) {
        praSale.setOrderByClause("id desc");
        return praSaleMapper.listByCondition(praSale);
    }

    /**
     * 根据id获取销售订单详细信息
     */
    @Override
    public PraSaleDto findById(Long id) {
        return praSaleMapper.findById(id);
    }

    /**
     * 保存销售订单
     *
     * @param praSale 销售订单
     * @return 结果
     */
    @Override
    public int save(PraSale praSale) {
        int count;
        if (praSale.getId() == null) {
            praSale.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
            praSale.setCreateTime(DateUtils.getNowDate());
            count = super.save(praSale);
        } else {
            praSale.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
            praSale.setUpdateTime(DateUtils.getNowDate());
            count = super.update(praSale);
        }
        return count;
    }
}
